using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Main.controls
{
    public partial class ShowPollResults : System.Web.UI.UserControl
    {
        private Poll _CurrentPoll;
        public Poll CurrentPoll
        {
            get { return _CurrentPoll; }
            set { _CurrentPoll = value; }
        }

        public OptionCollection CurrentOptions;
        protected void Page_Load(object sender, EventArgs e)
        {
            string data = "";
            string ops = "";
            int totalvotes = 0;
            CurrentOptions = new OptionCollection();
            CurrentOptions.FillByPollId(CurrentPoll.ID);
            foreach (Option op in CurrentOptions)
            {
                totalvotes += op.TotalVotes;
                ops += op.PollOption + "|";
            }
            if (totalvotes != 0)
            {
                foreach (Option op in CurrentOptions)
                {
                    data += Convert.ToString((op.TotalVotes / totalvotes * 100)) + ",";
                }

                data = data.Substring(0, data.Length - 1);
                ops = ops.Substring(0, ops.Length - 1);
                resultschart.Src = "http://chart.apis.google.com/chart?cht=p3&chd=t:" + data + "&chs=300x100&chl=" + ops;
            }
        }
    }
}